<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>管理系统</title>
    <meta name="description" content="管理系统">
    <meta name="keywords" content="管理系统">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script src="../plugins/echarts/echarts.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }
        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>管理<small>管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>管理</el-breadcrumb-item>
            <el-breadcrumb-item>管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="名称/类别" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                <el-button type="primary" class="butT" @click="countBank()">统计-柱状图</el-button>
                <el-button type="primary" class="butT" @click="exportExcel()">导出Excel</el-button>
            </div>
            <div class="boxMain">
                <el-upload action="/one/importData.do"
                           name="excelFile"
                           :show-file-list="false"
                           :on-success="handleSuccess"
                           :before-upload="beforeUpload">
                    <el-button type="primary">导入</el-button>
                </el-upload>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="studentName" label="学生名称" align="center"></el-table-column>
                <el-table-column prop="studentCode" label="学生编号" align="center"></el-table-column>
                <el-table-column  label="是否在校" align="center">
                    <template slot-scope="scope">
                        <span v-if="scope.row.zt=='1'">在校</span>
                        <span v-if="scope.row.zt=='2'">休学</span>
                        <span v-if="scope.row.zt=='3'">退学</span>
                    </template>
                </el-table-column>
                <el-table-column prop="studentAge" label="学生年龄" align="center"></el-table-column>
                <el-table-column  label="学生性别" align="center">
                    <template slot-scope="scope">
                        <span v-if="scope.row.studentSex=='1'">男</span>
                        <span v-if="scope.row.studentSex=='2'">女</span>
                    </template>
                </el-table-column>
                <el-table-column  label="学生专业" align="center">
                    <template slot-scope="scope">
                        <span v-if="scope.row.studentDid=='1'">大数据</span>
                        <span v-if="scope.row.studentDid=='2'">全栈</span>
                    </template>
                </el-table-column>
                <el-table-column prop="studentBirthday" label="出生日期" align="center"></el-table-column>
                <el-table-column label="学生头像" align="center">
                    <template slot-scope="scope">
                        <img :src="scope.row.studentImg" width="100px" height="60px">
                    </template>
                </el-table-column>
                <el-table-column  label="爱好" align="center">
                    <template slot-scope="scope">
                        <span v-if="scope.row.hobby.includes ('1')">抽烟</span>
                        <span v-if="scope.row.hobby.includes ('2')">喝酒</span>
                        <span v-if="scope.row.hobby.includes ('3')">烫头</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleYes(scope.row)">通过</el-button>
                        <el-button type="primary" size="mini" @click="handleNo(scope.row)">拒绝</el-button>
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="学生名称" prop="studentName">
                                                <el-input v-model="formData.studentName"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="学生编号" prop="studentCode">
                                                <el-input v-model="formData.studentCode"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="是否在校" prop="zt">
                                                <el-radio-group v-model="formData.zt" >
                                                    <el-radio label="1">在校</el-radio>
                                                    <el-radio label="2">休学</el-radio>
                                                    <el-radio label="3">退学</el-radio>
                                                </el-radio-group>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="学生年龄" prop="studentAge">
                                                <el-input type="number" v-model="formData.studentAge"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="学生性别">
                                                <el-radio-group v-model="formData.studentSex" >
                                                    <el-radio label="1">男</el-radio>
                                                    <el-radio label="2">女</el-radio>
                                                </el-radio-group>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="学生专业" prop="did">
                                                <el-select v-model="formData.did"  placeholder="请选择校区">
                                                    <el-option label="大数据" value="1"></el-option>
                                                    <el-option label="全栈" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="出生日期" prop="studentBirthday">
                                                <el-date-picker v-model="formData.studentBirthday"  type="date" placeholder="选择日期"  style="width: 100%;"></el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="学生爱好" prop="hobby">
                                                <el-checkbox-group v-model="formData.hobby">
                                                    <el-checkbox label="1">抽烟</el-checkbox>
                                                    <el-checkbox label="2">喝酒</el-checkbox>
                                                    <el-checkbox label="3">烫头</el-checkbox>
                                                </el-checkbox-group>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="学生头像">
                                                <el-upload action="/one/upload.do"
                                                           name="imgFile"
                                                           :show-file-list="false"
                                                           :on-success="handleSuccess"
                                                           :before-upload="beforeUpload">
                                                    <el-button type="primary">上传文件</el-button>
                                                </el-upload>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
							<el-tab-pane label="老师信息" name="second">
                                        <div class="checkScrol">
                                            <table class="datatable">
                                                <thead>
                                                <tr>
                                                    <th>选择</th>
                                                    <th>老师编码</th>
                                                    <th>老师名称</th>
                                                    <th>老师年龄</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                <tr v-for="c in tableData">
                                                    <td>
                                                        <input :id="c.id" v-model="checkitemIds" type="checkbox" :value="c.id">
                                                    </td>
                                                    <td><label :for="c.id">{{c.studentCode}}</label></td>
                                                    <td><label :for="c.id">{{c.studentName}}</label></td>
                                                    <td><label :for="c.id">{{c.studentAge}}</label></td>
                                                </tr>
                                                </tbody>
                                            </table>
                                        </div>
                                    </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑" :visible.sync="dialogFormVisible4Edit">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="学生名称" prop="studentName">
                                                    <el-input v-model="formData.studentName"/>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="学生编号" prop="studentCode">
                                                    <el-input v-model="formData.studentCode"/>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="24">
                                                <el-form-item label="是否在校" prop="zt">
                                                    <el-radio-group v-model="formData.zt" >
                                                        <el-radio label="1">在校</el-radio>
                                                        <el-radio label="2">休学</el-radio>
                                                        <el-radio label="3">退学</el-radio>
                                                    </el-radio-group>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="学生年龄" prop="studentAge">
                                                    <el-input type="number" v-model="formData.studentAge"/>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="学生性别">
                                                    <el-radio-group v-model="formData.studentSex" >
                                                        <el-radio label="1">男</el-radio>
                                                        <el-radio label="2">女</el-radio>
                                                    </el-radio-group>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="学生专业" prop="did">
                                                    <el-select v-model="formData.did"  placeholder="请选择校区">
                                                        <el-option label="大数据" value="1"></el-option>
                                                        <el-option label="全栈" value="2"></el-option>
                                                    </el-select>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="出生日期" prop="studentBirthday">
                                                    <el-date-picker v-model="formData.studentBirthday"  type="date" placeholder="选择日期"  style="width: 100%;"></el-date-picker>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="24">
                                                <el-form-item label="学生爱好" prop="hobby">
                                                    <el-checkbox-group v-model="formData.hobby">
                                                        <el-checkbox label="1">抽烟</el-checkbox>
                                                        <el-checkbox label="2">喝酒</el-checkbox>
                                                        <el-checkbox label="3">烫头</el-checkbox>
                                                    </el-checkbox-group>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="24">
                                                <el-form-item label="学生头像">
                                                    <el-upload action="/one/upload.do"
                                                               name="imgFile"
                                                               :show-file-list="false"
                                                               :on-success="handleSuccess"
                                                               :before-upload="beforeUpload">
                                                        <el-button type="primary">上传文件</el-button>
                                                    </el-upload>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                    </el-form>
                            </el-tab-pane>
							<el-tab-pane label="老师信息" name="second">
                                        <div class="checkScrol">
                                            <table class="datatable">
                                                <thead>
                                                <tr>
                                                    <th>选择</th>
                                                    <th>老师编码</th>
                                                    <th>老师名称</th>
                                                    <th>老师年龄</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                <tr v-for="c in tableData">
                                                    <td>
                                                        <input :id="c.id" v-model="checkitemIds" type="checkbox" :value="c.id">
                                                    </td>
                                                    <td><label :for="c.id">{{c.studentCode}}</label></td>
                                                    <td><label :for="c.id">{{c.studentName}}</label></td>
                                                    <td><label :for="c.id">{{c.studentAge}}</label></td>
                                                </tr>
                                                </tbody>
                                            </table>
                                        </div>
                                    </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑标签弹层 -->
            <el-dialog title="总金额统计" :visible.sync="dialogFormVisible4Echarts">
                <div id="chart1" style="height:400px;"></div>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogFormVisible4Echarts = false">取消</el-button>
                </div>
            </el-dialog>
        </div>
    </div>
</div>
</body>

<script>
    var vue = new Vue({
        el: '#app',
        data:{
            activeName:'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,//当前页码
                pageSize:5,//每页显示的记录数
                total:100,//总记录数
                queryString:null,//查询条件
            },
            dataList: [],//列表数据
            formData: {zt:"1",hobby:[]},//表单数据
            tableData:[],//新增和编辑表单中对应的检查项列表数据
            checkitemIds:[],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Echarts:false,
            dialogFormVisible4Edit:false,//控制编辑窗口显示/隐藏
            rules: {//校验规则
                sid: [{ required: true, message: '为必填项', trigger: 'blur' }],
                studentName: [{ required: true, message: '为必填项', trigger: 'blur' }],
                studentCode: [{ required: true, message: '为必填项', trigger: 'blur' }],
                zt: [{ required: true, message: '为必填项', trigger: 'blur' }],
                studentSex: [{ required: true, message: '为必填项', trigger: 'blur' }],
                did: [{ required: true, message: '为必填项', trigger: 'blur' }],
                studentBirthday: [{ required: true, message: '为必填项', trigger: 'blur' }],
                hobby: [{ required: true, message: '为必填项', trigger: 'blur' }],
                studentAge: [{ required: true, min:2,max:5,message: '必须为数字，且长度在2-5', trigger: 'blur' }]
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();
        },
        methods: {
            //编辑
            handleEdit() {
                //发送ajax请求，将修改后的表单数据（检查组基本信息、勾选的检查项）提交到后台进行处理
                this.$refs['dataEditForm'].validate((valid) => {
                    if(valid){
                        // this.formData.hobby = this.formData.hobby.join(",");
                        axios.post("/one/edit.do?checkitemIds="+this.checkitemIds,this.formData).then((res) => {
                            //关闭编辑窗口
                            this.dialogFormVisible4Edit = false;
                        this.$message({
                            type:res.data.flag?'success':'error',
                            message:res.data.message
                        });
                    }).catch((res)=>{
                            if(res.message.includes("403")) {
                                this.$message.error("无操作权限！")
                            }
                        }).finally(() =>{
                            this.findPage();
                    });
                    }else{
                        //表单校验不通过
                        this.$message.error("数据校验失败，请检查你的输入信息是否正确！");
                return false;
            }
            });
            },
            //添加
            handleAdd () {
                //alert(this.checkitemIds);
                this.$refs['dataAddForm'].validate((valid) => { //获取 ref属性是dataEditForm的表单   validate表单检验的方法
                    // valid  描述的表单提交的结果(true  false)  true表单成功校验 false 表单校验失败
                    if(valid){
                        //发送ajax请求，将表单数据提交到后台进行处理
                        // this.formData.hobby = this.formData.hobby.join(",");
                        axios.post("/one/add.do?checkitemIds="+this.checkitemIds,this.formData).then((res) => {
                            //关闭新增窗口
                            this.dialogFormVisible = false;
                        this.$message({
                            type:res.data.flag?'success':'error',
                            message:res.data.message
                        });
                    }).catch((res)=>{
                            if(res.message.includes("403")) {
                                this.$message.error("无操作权限！")
                            }
                        }).finally(() => {
                            //重新进行分页查询
                            this.findPage();
                    });
                    }else{
                        //表单校验不通过
                        this.$message.error("表单数据校验失败!");
                return false;
            }
            });
            },
            //分页查询
            findPage() {
                //发送ajax请求，提交分页相关参数
                axios.post("/one/findPage.do",this.pagination).then((res) => {
                    //为VUE对象的模型数据赋值，基于双向数据绑定展示到页面
                    this.dataList = res.data.rows;//当前页展示的数据集合
                this.pagination.total = res.data.total;//总数据量
            }).catch((res)=>{
                    if(res.message.includes("403")) {
                        this.$message.error("无操作权限！")
                    }
                });
            },
            // 重置表单
            resetForm() {
                this.formData = {zt:"1",hobby:[]};
            },
            // 弹出添加窗口
            handleCreate() {
                this.resetForm();
                this.dialogFormVisible = true;
                //发送ajax请求，查询所有的检查项信息，转为json，赋值给tableData
                this.activeName = 'first';//默认选中first对应的tab
				  //查询所有老师信息  上级信息
                axios.get("/one/findAllTeacher.do").then(res=>{
                      this.tableData = res.data;
                })
            },
            // 弹出编辑窗口
            handleUpdate(row) {
                //弹出编辑窗口
                this.dialogFormVisible4Edit = true;
                this.activeName = 'first';
                //用于基本信息的回显
                this.formData = row;
                // this.formData.hobby = this.formData.hobby.split(",");//处理多选框
				  
				   //查询所有老师信息  上级信息
				 axios.get("/one/findAllTeacher.do").then(res=>{
                      this.tableData = res.data;
                });
				 //根据学生sid查询关联的老师tid
                axios.get("/student/findTidBySid.do?id="+row.id).then(res=>{
                    this.checkitemIds = res.data;
                });
				
				
            },
            handleYes(row) {
                this.$confirm("确定吗？","提示",{//确认框
                    type:'warning'
                }).then(()=>{
                    //用户点击确定按钮，发送ajax请求，将检查项ID提交到Controller进行处理
                    axios.get("/one/updateYes.do?id=" + row.id).then((res) => { //点击确定执行的操作
                        //重新进行分页查询
                        this.findPage();
                this.$message({
                    type:res.data.flag?'success':'error',
                    message:res.data.message
                });
            }).catch((res)=>{
                        if(res.message.includes("403")) {
                            this.$message.error("无操作权限！")
                        }
                    });
            }).catch(()=>{ //点击取消执行的操作
                    this.$message({
                        type:'info',
                        message:'操作已取消'
                    });
            });
            },
            handleNo(row) {
                this.$confirm("确定吗？","提示",{//确认框
                    type:'warning'
                }).then(()=>{
                    //用户点击确定按钮，发送ajax请求，将检查项ID提交到Controller进行处理
                    axios.get("/one/updateNo.do?id=" + row.id).then((res) => { //点击确定执行的操作
                        //重新进行分页查询
                        this.findPage();
                this.$message({
                    type:res.data.flag?'success':'error',
                    message:res.data.message
                });
            }).catch((res)=>{
                        if(res.message.includes("403")) {
                            this.$message.error("无操作权限！")
                        }
                    });
            }).catch(()=>{ //点击取消执行的操作
                    this.$message({
                        type:'info',
                        message:'操作已取消'
                    });
            });
            },
            //上传之前进行文件格式校验
            beforeUpload(file){
                return true;
            },
            //上传成功提示
            handleSuccess(response, file) {
                if(response.flag){
                    this.findPage();
                    this.formData.pic=response.data;
                    this.$message({
                        message: response.message,
                        type: 'success'
                    });
                }else{
                    this.$message.error(response.message);
                }
            },
            // 弹出echarts
            countBank() {
                // 弹框
                this.dialogFormVisible4Echarts = true;
                this.$nextTick(() => {
                    axios.get("/one/getCount.do").then((res)=>{
                        // 基于准备好的dom，初始化echarts实例

                        //柱状图、折线图、曲线 x轴y轴都是数组['名称'] [数量]
                        //x轴是数组['名称'] ,y轴[{name:名称,value:数量}]

                        var myChart1 = echarts.init(document.getElementById('chart1'));
                          var xdata=[];
                          var ydata=[];
                          res.data.forEach(function(data){
                              xdata.push(data.name);
                              ydata.push({name:data.name,value:data.num})
                          })


			   var option = {
                    title : {
                        text : '初始化完毕，setOption填入数值'
                    },
                    tooltip : {},
                    legend : {
                    },
                    xAxis : {
                        data : res.data.data.names
                    },
                    yAxis : {},
                    series : [ {
                        name : "统计信息",
                        type : 'bar',
                        data : res.data.data.nums,
                    } ]
                };
                myChart1.setOption(option);
            });
            });
            },
            exportExcel(){
                window.location.href = '/one/exportOneReport.do';
            },
            //切换页码
            handleCurrentChange(currentPage) {
                //为模型数据赋值（当前页面）
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            // 删除
            handleDelete(row) {
                //先删除中间表
                //再删除检查组本身
                //alert(row.id);
                this.$confirm("你确定要删除当前数据吗？","提示",{//确认框
                    type:'warning'
                }).then(()=>{
                    //用户点击确定按钮，发送ajax请求，将检查项ID提交到Controller进行处理
                    axios.get("/one/delete.do?id=" + row.id).then((res) => { //点击确定执行的操作
                        if(res.data.flag){
                    //执行成功
                    //弹出成功提示信息
                    this.$message({
                        type:'success',
                        message:res.data.message
                    });
                    //重新进行分页查询
                    this.findPage();
                }else{
                    //执行失败
                    this.$message.error(res.data.message);
                }
            }).catch((res)=>{
                        if(res.message.includes("403")) {
                            this.$message.error("无操作权限！")
                        }
                    });
            }).catch(()=>{ //点击取消执行的操作
                    this.$message({
                        type:'info',
                        message:'操作已取消'
                    });
            });
            }
        }
    })
</script>
</html>
